
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#pragma once

#include "new.h"

//sdl is used to create the window and render the pictures
#include "SDL.h"

/*Class to handle the display of the generated images.	*/
/*This class is a singleton and should be accessed		*/
/*using the VISU macro.									*/			
class CVisualisation
{

private:
	//unique instance of CVisualisation class
	static CVisualisation* m_instance; 

	//window width
	unsigned int m_width;

	//window height
	unsigned int m_height;

	//bits per pixel
	unsigned int m_bpp;

	//screen buffer
	char* m_screenBuffer;

	//screen buffer with reversed line
	char* m_reverseScreenBuffer; 

	//sdl surface object used as interface for the screen buffer to access the window
	SDL_Surface* m_surfaceScreenBuffer;

	//sdl surface representing the window
	SDL_Surface* m_window;

	//sdl surface object for the reversed screen buffer used to save into BMP file
	SDL_Surface* m_surfaceReversedScreenBuffer;

private:
	//Constructor
	CVisualisation(void);

	//Destructor
	~CVisualisation(void);

public:
	//return the unique instance of the CVisualisation class
	static CVisualisation& getInstance();

	//delete the singleton
	void close();

	//initialise the window
	bool init(unsigned int width, unsigned int height, unsigned int bpp);

	//create the reverse screen buffer from the current screen buffer
	bool createReverseScreenBuffer();

	//prepare sdl to render
	void preRender();

	//render on the screen
	void doRender();

	//refresh window
	void postRender();

	//get a pointer to the screen buffer
	char* getScreenBuffer() const;

	//get a pointer to the reverse screen buffer
	char* getReverseScreenBuffer() const;

	//save the current screen buffer into a bmp file
	bool saveScreenBufferToBMP(const char* filename)const;

	//save the current reversed screen buffer into a bmp file (update the reversed screen buffer first)
	bool saveReversedScreenBufferToBMP(const char* filename)const;
};

//macro used to access the Visualisation singleton
#define VISU CVisualisation::getInstance()

